﻿<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Map,java.util.HashMap" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.general.BaseBean" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="bb" class="weaver.general.BaseBean" scope="page" />
<%!
/**
 * 
 * @Title: getFormFieldMap
 * @Description: TODO(根据表单id和明细表序号[从1开始计算明细表]获取字段列表)
 * @param @param formid
 * @param @param num
 * @param @return 设定文件
 * @return Map<String,String> 返回类型
 * @throws
 */
public Map<String, String> getFormFieldMap(int formid, String num) {
	Map<String, String> array = new HashMap<String, String>();
	RecordSet rs = new RecordSet();
	formid = Math.abs(formid);
	String sql = "";
	sql = "select tablename from workflow_bill where id=-"+formid;
	rs.execute(sql);
	if(rs.next()){
		String tablename = Util.null2String(rs.getString("tablename")).toLowerCase();
		if ("0".equals(num)) {
			sql = "select b.id,b.fieldname,b.detailtable from workflow_billfield b where b.billid=-"+ formid+ " and (b.detailtable = '' or b.detailtable is null) ";
		} else {
			sql = "select b.id,b.fieldname,b.detailtable from workflow_billfield b where b.billid=-"+ formid+ " and b.detailtable='"+tablename+"_dt" + num + "'";
		}
		rs.execute(sql);
		while (rs.next()) {
			array.put(Util.null2String(rs.getString("fieldname")).toLowerCase(),Util.null2String(rs.getString("id")));
		}
	}
	return array;
}
%>

<%
User user = HrmUserVarify.getUser (request , response) ;
if(user == null)  return ;
/**
String isIE = (String)session.getAttribute("browser_isie");
if (isIE == null || "".equals(isIE)) {
	isIE = "true";
	session.setAttribute("browser_isie", "true");
}
**/
int type = Util.getIntValue(request.getParameter("type"));//0：查看；1：创建；2：编辑；3：监控
int formmodeid = Util.getIntValue(request.getParameter("formmodeid"));//模块id
String billid = Util.null2String(request.getParameter("billid"));//数据id
int formid = Util.getIntValue(request.getParameter("formid"));//表单id
String url = Util.null2String(request.getParameter("url"));//请求url串

int resourceId = user.getUID();//当前用户的id
//查询当前用户所在的分部
RecordSet rs1 = new RecordSet();
int value = -1;
String sql1 = "";
sql1 = "select * from hrmresource where id="+resourceId;
rs1.execute(sql1);
if(rs1.next()){
	value  = Util.getIntValue(rs1.getString("subcompanyid1"));
}


Calendar today = Calendar.getInstance();
String currentdate = Util.add0(today.get(Calendar.YEAR), 4) + "-" +
                     Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" +
                     Util.add0(today.get(Calendar.DAY_OF_MONTH), 2) ;//当前日期 格式为 1992-01-01
String currenttime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":" +
                     Util.add0(today.get(Calendar.MINUTE), 2) + ":" +
                     Util.add0(today.get(Calendar.SECOND), 2) ;//当前时间 格式为11:30:30
%>
<%-- 获取表单字段map的代码段 2016-4-19 12:15:56 start --%>
<%

Map<String, String> arrayM = new HashMap<String, String>();
arrayM = getFormFieldMap(formid, "0");//主表字段map<name,id>

%>
<%-- 获取表单字段map的代码段 2016-4-19 12:15:56 start --%>
<%
/**此处可以编写自己的自定义java代码***/
	//获取上周周一 周日的日期
	Calendar cal = Calendar.getInstance(); 
	int n = cal.get(Calendar.DAY_OF_WEEK) - 1; 
	if (n == 0) { 
	    n = 7; 
	} 
	cal.add(Calendar.DATE, -(7 + (n - 1)));// 上周一的日期 
	Date monday = cal.getTime(); 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String monDay = sdf.format(monday);
	cal.add(Calendar.DATE, 6); 
	Date sunday = cal.getTime(); 
	String sunDay = sdf.format(sunday);
	//-----------获取当前日期为星期几
	int weekDay = today.get(Calendar.DAY_OF_WEEK)-1;

%>
<script type="text/javascript"  src ="/js/workflow/VCEventHandle_wev8.js" ></script>
<script type="text/javascript">
//----表单建模标准字段获取-----
var stype = "<%=type%>";//0：查看；1：创建；2：编辑；3：监控

if(stype=="0"||stype=="3"){//查看||监控
}
if(stype=="1"||stype=="2"){//创建||编辑
}

//-----字段id获取-----
var nf_mafi = "<%=arrayM.get("nf")%>";//年份-M
var zb_mafi = "<%=arrayM.get("zb")%>";//年份-M
//-------------------------------------------
var weekDay = <%=weekDay%>;
var monDay = "<%=monDay%>";
var sunDay = "<%=sunDay%>";
//-----周别起始日期----
var zqsrq_mafi = "<%=arrayM.get("zqsrq")%>";
//-----周别结束日期----
var zjsrq_mafi = "<%=arrayM.get("zjsrq")%>";
//------------------------------------------
var  value1 = <%=value%>;
//var number = 1;
jQuery(document).ready(function(){
	//取得button按钮的节点  用来记录点击次数
	/* var addbutton0 = document.getElementById("$addbutton0$");
	jQuery(addbutton0).click(function(){
		number = number + 1;
	}); */
	if(stype=="1"||stype=="2"){		
		checkCustomize = function (){
			//var flagyb = checkYbTb();
			// if(flagyb){
			// 	return flagyb;
			// }
			//if(value1 == 5 || value1 == 0){
				//return true;	
			//}else if(flagyb){
				//var flag01 = Checkbox01();
			//	var flag02 = Checkbox02();
			//	return flag02;
				//return flag01 && flag02;
			//}
			return true;	
			
	    }
	}
});

//---填报周别只能为当前日期的上一周的
function Checkbox01(){
	var nf_mafv = jQuery("#field"+nf_mafi).val();//年份---实际值
    var zb_mafe = jQuery("#field"+zb_mafi+"span").val();//周别---显示值
    //------------获取周别日期
    var zqsrq = jQuery("#field"+zqsrq_mafi).val();
    var zjsrq = jQuery("#field"+zjsrq_mafi).val();
    
    if(zqsrq == monDay && zjsrq == sunDay){
    	if(weekDay == 1 || weekDay == 2 || weekDay == 3){
    		return true;
    	}else{
    		alert("上报时间为周一至周三");
    		return false;
    	}
    }else{
    	alert("请录入上周周报");
    	return false;
    } 
}
// 用来验证类别是否重复
function Checkbox02(){

	var subrow = jQuery("input[name=check_mode_0]");//check_mode_0 中的0表示第一个子表，子表没一行都有一个隐藏元素，记录当前行号
	var array = new Array();
	for(var i=0; i<subrow.length; i++){
		var row = subrow.get(i).value;//每一行的行号
		//var val =  jQuery("#field5882_"+row+"span").value;
		var val =  jQuery("#field5882_"+row).val();
		if(val!=""){
			array.push(val);
		}
		//array[i] = jQuery("#field5882_"+row+"span").text();
	}
	
	for(var j = 0; j < array.length-1; j++){
		for(var k = j+1; k < array.length; k++){
			if(jQuery.trim(array[j]) == jQuery.trim(array[k])){
				alert("类别重复,请重新输入!");
				return false;
			}
		}
	} 
	return true; 
}

$.ajaxSetup({
	async : false
});

//验证是否需要填写月报
	function checkWhetherFillInMonthlyReport() {



		var yy;
		var flag11 = false;
		$.get('/interface/wangjie/yuebao/checkWhetherFillInMonthlyReport.jsp',function (data) {
			if(!data){
			// alert('没有此周别！不允许填写月报');
				yy =  '没有此周别！不允许填写月报';
			};
			//获取周别是否为特定周和当前是否本周一二三
			var zhoubie = data.zhoubie;//周别
			var isyb = data.isyb;//是否特定周
			var nowDate = data.nowDate;//当前服务器时间
			var isZ1Z2Z3 = data.isZ1Z2Z3;//是否周一周二周三
			if(isyb == 'true'){
				//判断是否周一二三
				if (isZ1Z2Z3 == 'true'){
					//判断是否填写月报
					$.get('/interface/wangjie/yuebao/getLastYueBao.jsp',function (data) {
						//遍历用户数据
						if($(data).size()>0){
							console.log("已经填写过月报拉！");
							flag11 = true;
							return;
						}
					},'json');
					console.log(flag11);
				if(flag11==true){
					console.log("============ff");
					return flag;
				}
                //应该填写月报，询问是否填写月报
                var checkyb = confirm("检测到本周需要填写月报是否打开月报填写页面？");
				if(checkyb){
					//弹出月报流程 /workflow/request/AddRequest.jsp?workflowid=37&isagent=0&beagenter=0&f_weaver_belongto_userid=
					redirectUrl = "http://baidu.com";
					var width = screen.availWidth/2 ;
					var height = screen.availHeight/2 ;
					var szFeatures = "top="+(height/2)+"px," ;
					szFeatures +="left="+(width/2)+"px," ;
					szFeatures +="width="+width+"," ;
					szFeatures +="height="+height+"," ;
					szFeatures +="directories=no," ;
					szFeatures +="status=yes,toolbar=no,location=no," ;
					szFeatures +="menubar=no," ;
					szFeatures +="scrollbars=yes," ;
					szFeatures +="resizable=yes" ; //channelmode
					//tagprj
					if(redirectUrl.indexOf("topage=%252Fproj%252Fprocess%252FRequestOperation.jsp%253Fmethod%253Dadd")>-1){
						parent.location.href=redirectUrl;
					}else{
						window.open("/workflow/request/AddRequest.jsp?workflowid=37&isagent=0&beagenter=0&f_weaver_belongto_userid=","",szFeatures) ;
					}
					//设置全局对象
					//  dlg = new window.top.Dialog(); //定义Dialog对象    
					//  dlg.currentWindow = window;    
					//  dlg.Model = false;　　　    
					//  dlg.Width = 1060; //定义长度    
					//  dlg.Height = 500;　　　    
					//  dlg.URL = "/workflow/request/AddRequest.jsp?workflowid=37&isagent=0&beagenter=0&f_weaver_belongto_userid=";　　　    
					//  dlg.Title = "title" ;    
					//  dlg.maxiumnable = true;　　　    
					//  dlg.show();
					//  window.dialog = dlg;
					//  console.log("====="+dlg);
					 //设置定时器

					 //setInterval("checkDlg()",2000);
					 //监听window.dialog
					 //关闭窗口  $("div[id^='_maxBtn_']").prev().click();


				}
            }else{
                //alert('周报只允许在周一、周二、周三填写，当前服务器日期：'+nowDate);
                yy = '周报只允许在周一、周二、周三填写，当前服务器日期：'+nowDate;
            }

        }else{
            yy = '本周不允许填写月报,当前周别：'+zhoubie;
            //alert('本周不允许填写月报,当前周别：'+zhoubie);
        }
    },'json');
	if(flag11==true){
		return flag11;
	}
  }

	// function checkDlg(){
	// 	if(window.dialog!=undefined){
	// 		console.log("存在窗口"+window.dialog);
	// 		return false;
	// 	}
	// 	//调用系统登录方法
	// 	alert("提交");
	// 	return true;
	// }	


	    /**
     * 判断是否可以填报
     */
    function checkYbTb(){
        /*$.

               	//应该填写月报，询问是否填写月报
                var checkyb = confirm("检测到本周需要填写月报是否打开月报填写页面？");
				if(checkyb){
					//弹出月报流程 /workflow/request/AddRequest.jsp?workflowid=37&isagent=0&beagenter=0&f_weaver_belongto_userid=
					redirectUrl = "http://baidu.com";
					var width = screen.availWidth/2 ;
					var height = screen.availHeight/2 ;
					var szFeatures = "top="+(height/2)+"px," ;
					szFeatures +="left="+(width/2)+"px," ;
					szFeatures +="width="+width+"," ;
					szFeatures +="height="+height+"," ;
					szFeatures +="directories=no," ;
					szFeatures +="status=yes,toolbar=no,location=no," ;
					szFeatures +="menubar=no," ;
					szFeatures +="scrollbars=yes," ;
					szFeatures +="resizable=yes" ; //channelmode
					//tagprj
					if(redirectUrl.indexOf("topage=%252Fproj%252Fprocess%252FRequestOperation.jsp%253Fmethod%253Dadd")>-1){
						parent.location.href=redirectUrl;
					}else{
						window.open("/workflow/request/AddRequest.jsp?workflowid=37&isagent=0&beagenter=0&f_weaver_belongto_userid=","",szFeatures) ;
					}

				}

            }
		});*/


       // return flag;
	   return true;
    }
</script>


